<?php

namespace App\Admin\Controllers;

use App\Models\ExhibitorMessageTaskExpire;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ExhibitorMessageTaskExpireController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '首页任务截止时间配置';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ExhibitorMessageTaskExpire());
        $grid->disableCreateButton();//隐藏新增
        $grid->column('type_id', __('exhibitor_message_task_expire.type_id'))->using(__('exhibitor_message_task_expire.type_array'));

        $grid->column('expire_time', __('exhibitor_message_task_expire.expire_time'));
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            //显示按钮、查看按钮
            $actions->disableView();
        });
        $grid->batchActions(function ($batch) {
            $batch->disableDelete();
        });
        $script = <<<EOT

var search = $('.btn-dropbox');
search.hide();
EOT;
        Admin::script($script);
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ExhibitorMessageTaskExpire::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('contents', __('Contents'));
        $show->field('exhibitor_message_id', __('Exhibitor message id'));
        $show->field('type_id', __('Type id'));
        $show->field('expire_time', __('Expire time'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ExhibitorMessageTaskExpire());

        $form->select('type_id', __('exhibitor_message_task_expire.type_id'))->options(__('exhibitor_message_task_expire.type_array'))->rules('required');
        $form->datetime('expire_time',__('exhibitor_message_task_expire.expire_time'))->format('YYYY-MM-DD')->rules('required');

        $form->tools(function ($tools) {
            // 去掉`删除`按钮
            $tools->disableDelete();

            // 去掉`查看`按钮
            $tools->disableView();

        });
        $form->footer(function ($footer) {

            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();
            // 去掉`查看`checkbox
            $footer->disableViewCheck();


        });
        $form->saving(function (Form $form) {
            $form->model()->exhibitor_message_id = 1;
            $form->expire_time = date('Y-m-d 23:59:59', strtotime($form->expire_time)); //结束时间取当日23：59：59


        });
        return $form;
    }
}
